package two_shang._11_09;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Employee {
    private int id;
    private String name;
    private double salary;

    public Employee(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public Employee() {
    }

    // Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String toString() {
        return "员工： [id=" + id + ", name=" + name + ", salary=" + salary + "]";
    }

}

public class Test01 {
    static public void removeEmployee(List<Employee> employeeList, int index) {
        if (index >= 0 && index < employeeList.size()) {
            employeeList.remove(index);
            System.out.println("员工删除成功！");
        } else {
            System.out.println("无法删除员工，指定位置超出范围！");
        }
    }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        List<Employee> employeeList = new ArrayList<>();

        // 添加三条员工信息到ArrayList中
        Employee emp1 = new Employee(1, "约翰", 5000.0);
        Employee emp2 = new Employee(2, "简", 6000.0);
        Employee emp3 = new Employee(3, "麦克", 7000.0);

        employeeList.add(emp1);
        employeeList.add(emp2);
        employeeList.add(emp3);

        // 显示员工信息
        for (Employee employee : employeeList) {
            System.out.println(employee);
        }

        System.out.println("请输入你要加入员工的索引位置，从0开始");
        int index = scanner.nextInt();
        Employee emp4 = new Employee(4, "但丁", 100.0);
        employeeList.add(index, emp4);

        for (Employee employee : employeeList) {
            System.out.println(employee);
        }

        System.out.println("请输入你要删除员工的索引位置，从0开始");
        index = scanner.nextInt();
        removeEmployee(employeeList, index);
        for (Employee employee : employeeList) {
            System.out.println(employee);
        }

        // 判断指定员工是否存在
        System.out.println("员工简是否存在：" + employeeList.contains(emp2));

        // 返回指定位置员工的索引值
        System.out.println("员工麦克的索引值：" + employeeList.indexOf(emp3));
    }
}

